package com.secsys.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.secsys.dto.StoCapitalizationDTO;
import com.secsys.model.TbStoCapitalization;
import com.secsys.model.TbStoStock;
import com.secsys.service.StoCapitalizationService;
import com.secsys.service.StoStockService;

public class StoCapitalizationServiceImpl extends ServiceImpl<TbStoCapitalization, Integer> implements
		StoCapitalizationService {

	private StoStockService stoStockService;
	
	@Override
	public List<StoCapitalizationDTO> queryStoStockdailyByStockCode(
			int stockCode) {
		TbStoStock tbStoStock=stoStockService.findByProperty("from TbStoStock where stockCode=?", String.valueOf(stockCode)).get(0);
		return queryStoStockdailyByTbStoStock(tbStoStock);
	}

	@Override
	public List<StoCapitalizationDTO> queryStoStockdailyByTbStoStock(
			TbStoStock tbStoStock) {
		String hql="from TbStoCapitalization as tsc where tsc.tbStoStock=?";
		return foreachGetDtoFromPojo(this.findByProperty(hql, tbStoStock)); 
	}


	/**
	 * 批量地将持久化对象POJO的List<TbStoCapitalization>转换成领域对象DTO的List<StoCapitalizationDTO>
	 * @param List<TbStoCapitalization>
	 * 			持久化对象POJO的List<TbStoCapitalization>
	 * @return	List<StoStockdailyDTO>
	 * 			领域对象DTO的List<StoCapitalizationDTO>
	 */
	private List<StoCapitalizationDTO> foreachGetDtoFromPojo(List<TbStoCapitalization> tbStoCapitalizationList){
		List<StoCapitalizationDTO> stoCapitalizationDTOList=new ArrayList<StoCapitalizationDTO>();
		for (TbStoCapitalization tbStoCapitalization : tbStoCapitalizationList) {
			stoCapitalizationDTOList.add(getDtoFromPojo(tbStoCapitalization));
		}
		return stoCapitalizationDTOList;
	}
			
	
	/**
	 * 将持久化对象POJO的TbStoCapitalization转换成领域对象DTO的StoCapitalizationDTO
	 * @param TbStoCapitalization
	 * 			持久化对象POJO的TbStoCapitalization
	 * @return	StoCapitalizationDTO
	 * 			领域对象DTO的StoCapitalizationDTO
	 */
	private StoCapitalizationDTO getDtoFromPojo(TbStoCapitalization tbStoCapitalization){
		StoCapitalizationDTO stoCapitalizationDTO=new StoCapitalizationDTO(
				tbStoCapitalization.getId(),tbStoCapitalization.getChangeDate(),
				tbStoCapitalization.getTotalCaptial(),tbStoCapitalization.getCirculateA(),
				tbStoCapitalization.getCirculateAFact(),tbStoCapitalization.getReason()
		);
		return stoCapitalizationDTO;
	}

	public StoStockService getStoStockService() {
		return stoStockService;
	}

	public void setStoStockService(StoStockService stoStockService) {
		this.stoStockService = stoStockService;
	}
	
}
